package com.k8.common.aop.internal.interceptor;

import com.k8.common.aop.internal.advice.AdviceOrderEnum;
import com.k8.common.aop.internal.advice.BeforeAdvice;
import com.k8.common.aop.internal.invocation.MethodInvocation;
import com.k8.common.util.AopUtil;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

public class BeforeMethodInterceptor extends ProxyMethodExecutor implements BeforeAdvice {
    public BeforeMethodInterceptor(Object target, Method targetMethod) {
        super(target, targetMethod);
    }

    @Override
    public int getAdviceOrder() {
        return BeforeAdvice.super.getAdviceOrder();
    }

    @Override
    boolean judgeArgument(Parameter parameter, Method targetMethod) {
        return AopUtil.judgeJoinAdviceArgs(parameter, AdviceOrderEnum.Before,targetMethod);
    }


    @Override
    Object invoke0(MethodInvocation invocation) throws Throwable {
        super.invokeAdvice();
        return invocation.proceed();
    }
}
